class Node:
	def __init__(self, idx, root = None):
		self.l = None
		self.r = None
		self.t = root
		self.idx = idx
	
	def root(self):
		print self.idx
		if self.isRoot():
			return self
		return self.t.root()

	def left(self):
		return self.l
	
	def right(self):
		return self.r

	def isRoot(self):
		return self.t == None

	def isLeaf(self):
		return self.l == None and self.r == None

	def addRNode(self, node):
		self.r = node
	
	def addLNode(self, node):
		self.l = node

	def __str__(self):
		s = str(self.idx)
		if self.r != None:
			s += ' '+self.r.__str__()
		if self.l != None:
			s += ' '+self.l.__str__()
		return s
